""""
    配置类
"""
from Background import Background
from Official import Img, Text


class ImgProject:
    """
    一个图片文案对象
    """

    def __init__(self, img: Img, title: Text = None, subheading: Text = None, substance: Text = None):
        self.img = img
        self.title = title
        self.subheading = subheading
        self.substance = substance


class ProjectItem:
    """
    一个项目
    """

    def __init__(self, path: str, background: Background):
        self.path = path
        self.background: Background = background
        self.project_list = []

    def add_project(self, project: ImgProject):
        """
        添加标题
        :param project: 一个图片
        """
        self.project_list.append(project)

    def save(self):
        """
        保存到文件系统
        """
        file_name = 1
        # 遍历标题图
        for project in self.project_list:
            if project.title is not None:
                # 插入标题
                self.background.insert_title(project.title)
            if project.subheading is not None:
                # 插入副标题
                self.background.insert_subheading(project.subheading)
            if project.substance is not None:
                # 插入内容
                self.background.insert_substance(project.substance)

            self.background.insert_img(project.img)
            # 保存
            self.background.save(self.path, str(file_name) + '.jpg')
            file_name = file_name + 1
            # 重置模板
            self.background.reset_template()
